Hands-On Design Patterns with Kotlin: Build scalable applications using traditional, reactive, and concurrent design patterns in Kotlin by Alexey Soshin

Hands-On Design Patterns with Kotlin: Build scalable applications using traditional, reactive, and concurrent design patterns in Kotlin by Alexey Soshin

Author:Alexey Soshin [Soshin, Alexey]
Language: eng
Format: epub
Tags: COM051230 - COMPUTERS / Software Development and Engineering / General, COM051280 - COMPUTERS / Programming Languages / Java, COM051240 - COMPUTERS / Software Development and Engineering / Systems Analysis and Design
Publisher: Packt Publishing
Published: 2018-06-14T23:00:00+00:00


thread(isDaemon = true) {

while(true) counter.gamesPlayed = 0

}

for (i in 1..1_000) {

counter.totalScore += Random().nextInt(100)

counter.gamesPlayed++

println(counter.average)

}

Soon enough, you'll receive ArithmeticException anyway. Our counter somehow becomes zero.

If you want your data classes to be immutable, be sure to specify all their properties as val (values), and not var (variables).

Immutable collections

I think that our junior developer learned their lesson. Instead, they produced this code, which is not very efficient, but which gets rid of those variables:

data class ScoreCollector(val scores: MutableList<Int> = mutableListOf())



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.